﻿using System;
using System.Data;
using Titan.FIS.Enum;

namespace Titan.FIS.LmsBalanceCollect
{
    public class DataExecProc
    {
        /// <summary>
        /// 插入试样样计算结果到采集表
        /// </summary>
        /// <param name="strTestCode"></param>
        /// <param name="iTestIndex"></param>
        /// <param name="strTestValue"></param>
        /// <param name="iTestMode"></param>
        /// <param name="iCType"></param>
        /// <param name="iSType"></param>
        /// <param name="strErrInfo"></param>
        /// <returns></returns>
        public static bool DoInsertCollectionData(string strTestCode, int iTestIndex, string strTestValue, string strAuto, int instrument, string weight, ref string strErrInfo)
        {
            var bResult = false;
            strErrInfo = string.Empty;
            var parms = new[]{    new Titan.DAS.Msg.Common.ProcParam{Name = "P_TESTCODE",Value = strTestCode,Direction = ParameterDirection.Input,DbType = Convert.ToInt32(Titan.DAS.Client.Data.ODB_Type.NVarchar2)},
                                  new Titan.DAS.Msg.Common.ProcParam{Name = "P_TESTINDEX",Value = iTestIndex,Direction = ParameterDirection.Input,DbType = Convert.ToInt32(Titan.DAS.Client.Data.ODB_Type.NVarchar2)},  
                                  new Titan.DAS.Msg.Common.ProcParam{Name = "P_TESTVALUE",Value = strTestValue,Direction = ParameterDirection.Input,DbType = Convert.ToInt32(Titan.DAS.Client.Data.ODB_Type.Decimal)},
                                  new Titan.DAS.Msg.Common.ProcParam{Name = "P_AUTONO",Value = strAuto,Direction = ParameterDirection.Input,DbType = Convert.ToInt32(Titan.DAS.Client.Data.ODB_Type.NVarchar2)},
                                  new Titan.DAS.Msg.Common.ProcParam{Name = "P_INSTRUMENT",Value = instrument,Direction = ParameterDirection.Input,DbType = Convert.ToInt32(Titan.DAS.Client.Data.ODB_Type.Decimal)},
                                  new Titan.DAS.Msg.Common.ProcParam{Name = "P_SAMPLEWEIGHT",Value = weight,Direction = ParameterDirection.Input,DbType = Convert.ToInt32(Titan.DAS.Client.Data.ODB_Type.Decimal)},
                                  new Titan.DAS.Msg.Common.ProcParam{Name = "P_TESTDATE",Value = DateTime.Now,Direction = ParameterDirection.Input,DbType = Convert.ToInt32(Titan.DAS.Client.Data.ODB_Type.Date)},
                                  new Titan.DAS.Msg.Common.ProcParam{Name = "P_ERRCODE",Value = 0,Direction = ParameterDirection.Output,DbType = Convert.ToInt32(Titan.DAS.Client.Data.ODB_Type.Decimal)},
                                  new Titan.DAS.Msg.Common.ProcParam{Name = "P_ERRMSG",Value = null,Direction = ParameterDirection.Output,DbType = Convert.ToInt32(Titan.DAS.Client.Data.ODB_Type.NVarchar2),Size=2000}};
            var modelProc = DAS.Client.Data.DataHelper.Instance.ExecProc(Common.UserInfo.UserName, Common.UserInfo.UserPwd, "PCK_LMSDATAINFO.INSERT_LMS_COLLECTIONDATA", parms);
            if (!modelProc.RSuccess || modelProc.RStatuCode != 1)
            {
                strErrInfo = string.Format("操作失败!\r\n错误代码:{0}  错误描述:{1}", modelProc.RStatuCode, modelProc.RStatuDesc);
            }
            else
            {
                strErrInfo = modelProc.RParams[modelProc.RParams.Length - 1].Value == null ? string.Empty : modelProc.RParams[modelProc.RParams.Length - 1].Value.ToString().Replace("null", "").Trim();
                if (!string.IsNullOrEmpty(strErrInfo)) return false;
                bResult = true;
            }
            return bResult;
        }




    }
}
